package com.hongxun.modules.bss.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.dao.APEstimateDao;
import com.hongxun.modules.bss.entity.APEstimateEntity;
import com.hongxun.modules.bss.service.APEstimateService;



@Service("aPEstimateService")
public class APEstimateServiceImpl implements APEstimateService {
	@Autowired
	private APEstimateDao aPEstimateDao;
	
	@Override
	public APEstimateEntity queryObject(String guid){
		return aPEstimateDao.queryObject(guid);
	}
	
	@Override
	public List<APEstimateEntity> queryList(Map<String, Object> map){
		return aPEstimateDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return aPEstimateDao.queryTotal(map);
	}
	
	@Override
	public void save(APEstimateEntity aPEstimate){
		if(aPEstimate.getGuid()==null||aPEstimate.getGuid().equals("")) {

			aPEstimate.setGuid(UUID.randomUUID().toString());
		}
		aPEstimateDao.save(aPEstimate);
	}
	
	@Override
	public void update(APEstimateEntity aPEstimate){
		aPEstimateDao.update(aPEstimate);
	}
	
	@Override
	public void delete(String guid){
		aPEstimateDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		aPEstimateDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<APEstimateEntity> entities) {
		for (APEstimateEntity d : entities) {
			if (d.getPEDatastate().equals("删除")) {
				aPEstimateDao.delete(d.getGuid());
			} else {
				APEstimateEntity apEstimateEntity = aPEstimateDao.queryObject(d.getGuid());
				if (apEstimateEntity == null) {
					aPEstimateDao.save(d);
				} else {
					aPEstimateDao.update(d);
				}
			}
		}
	}
}
